﻿{extend name='public/base' /}

{block name='seo' /}
<title>{$title|default='标题'}</title>
<meta name="keywords" content="{$keywords|default='关键字'}">
<meta name="description" content="{$desc|default='描述'}">
{/block}


{block name='content' /}
<section class="Hui-article-box">
	<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页
		<span class="c-gray en">&gt;</span>
		数据管理
		<span class="c-gray en">&gt;</span>
		数据列表 <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a> </nav>
	<div class="Hui-article">
		<div class="cl pd-20">
			<p>
				{php}echo "今天是 " . date("Y年m月d日"). date("m") . "<br>";{/php}
			</p>
		</div>
	</div>
	
	<div class="Hui-article">
		<article class="cl pd-20">
			<div class="cl pd-5 bg-1 bk-gray mt-20">
				<span class="l">
					<span>年度：&nbsp;
						<select name="year" id="year">
							<option value="">选择年份</option>
							{for start='2010' end='date("Y")+2' comparsion='lt' name='i' step='1'}
								{if condition="$i == date('Y')"}
									<option value="{$i}" selected="selected">{$i}</option>
								{else /}
									<option value="{$i}">{$i}</option>
								{/if}
							{/for}
						</select>
					</span>
					<span>月份：&nbsp;
						<select name="month" id="month">
							<option value="">选择月份</option>
							{for start='1' end='12' comparsion='lt' name='i' step='1'}
								{if condition="$i == date('m')"}
									<option value="{$i}" selected="selected">{$i}</option>
								{else /}
									<option value="{$i}">{$i}</option>
								{/if}
							{/for}
						</select>
					</span>
					<span>周度：&nbsp;
						<select name="week" id="week">
							<option value="">选择周度：</option>
							<option value="1">01</option>
							<option value="2">02</option>
							<option value="3">03</option>
							<option value="4">04</option>
							<option value="5">05</option>
						</select>
					</span>
					<span>厂家：&nbsp;
						{eq name="$Think.session.user_info.username" value="admin"}
						<select name="week" id="oem">
							<option value="">选择厂家：</option>
							{volist name="oem" id="vo"}
								{if condition="$vo.name == $Think.session.user_info.oem"}
									<option value="{$vo.name}" selected="selected">{$vo.name}</option>
								{else /}
									<option value="{$vo.name}">{$vo.name}</option>
								{/if}
							{/volist}
						</select>
						{/eq}
						<select name="week" id="oem">
							<option value="{$Think.session.user_info.oem}">
								{$Think.session.user_info.oem}
							</option>
						</select>
					</span>
					<a href="javascript:;" onclick="admin_add('添加数据',
					'./dataAddView'+'/yy/'+$('#year').val()+'/mm/'+$('#month').val()+
					'/ww/'+$('#week').val()+'/oem/'+$('#oem').val(),
					'800','600')" class="btn btn-primary radius">
					<i class="Hui-iconfont">&#xe600;</i> 添加数据</a>
				</span>
				<span class="r">共有数据：<strong>{$count}</strong> 条</span>
			</div>
			
			<table class="table table-border table-bordered table-bg">
				<thead>
					<tr>
						<th scope="col" colspan="9">信息列表</th>
					</tr>
					<tr class="text-c">
						<th width="80">年份</th>
						<th width="80">月份</th>
						<th width="80">周度</th>
						<th width="130">厂商</th>
						<th width="130">批发</th>
						<th width="130">零售</th>
						<th width="100">操作</th>
					</tr>
				</thead>
				<tbody>
				
				{volist name="list" id="vo"}
					<tr class="text-c">
						<td>{$vo.yy}</td>
						<td>{$vo.mm}</td>
						<td>{$vo.ww}</td>
						<td>{$vo.dname}</td>
						<td>{$vo.wholesale}</td>
						<td>{$vo.retail}</td>
						<td class="td-manage">
							<!--切换启用与禁用图标-->
							<!--只允许admin有权启用或停用-->
							
							<a title="编辑" href="javascript:;" onclick="admin_edit('管理员编辑','{:url("data/dataEditView",["dname"=>$vo.dname,"yy"=>$vo.yy,"mm"=>$vo.mm,"ww"=>$vo.ww])}','800','500')" class="ml-5" style="text-decoration:none">
								<i class="Hui-iconfont">&#xe6df;</i>
							</a>
							
							<!--只允许admin有删除权限-->
							{eq name="$Think.session.user_info.username" value="admin"}
							<!-- <a title="删除" href="javascript:;" onclick='admin_del(this,{$vo.yy}_{$vo.mm}_{$vo.ww}_{$vo.dname})' class="ml-5" style="text-decoration:none"> -->
							<a title="删除" href="javascript:;" onclick='admin_dell(this)' class="ml-5" style="text-decoration:none">
								<i class="Hui-iconfont">&#xe6e2;</i>
							</a>
							{/eq}


						</td>
					</tr>
				{/volist}

				</tbody>
			</table>
		</article>
	</div>
</section>
{/block}


{block name='js'}

<script type="text/javascript">
/*
	参数解释：
	title	标题
	url		请求的url
	id		需要操作的数据id
	w		弹出层宽度（缺省调默认值）
	h		弹出层高度（缺省调默认值）
*/
$(document).ready(function(){
	$('#menu-comments dt').attr('class','selected');
	$('#menu-comments dd').attr('style','display: block;');
});
/*管理员-增加*/

function admin_dell(obj){
	alert("1231");
	
	yy = $(obj).parents("tr").children('td').eq(0).html();
	mm = $(obj).parents("tr").children('td').eq(1).html();
	ww = $(obj).parents("tr").children('td').eq(2).html();
	oem = $(obj).parents("tr").children('td').eq(3).html();

	$.ajax({
		url: "{:url('data/deleteData')}",
		type: 'POST',
		data: {"yy":yy,"mm":mm,"ww":ww,"oem":oem},
		dataType: "json",
		success: function(data){
			alert(data.message);

		}
		
	});
}

/*管理员-删除*/
function admin_del(obj,id){
	layer.confirm('确认要删除吗？',function(index){
		//此处请求后台程序，下方是成功后的前台处理……
		// $.get("{:url('user/deleteUser')}",{id:id})
		$.get("{:url('data/deleteData')}",{"id":id})
		
		$(obj).parents("tr").remove();
		layer.msg('已删除!',{icon:1,time:1000});
	});
}

function admin_addv2(title,w,h){
	
	// if (($("#week").val() == "") or ($("#oem").val() == "") {
	// 	alert('信息不能为空，请填写完整。');
	// };

	url = 'http://localhost/myphp8/public/index/data/dataAddView'+'/yy/'+$('#year').val()+'/mm/'+$('#month').val()+'/ww/'+$('#week').val()+'/oem/'+$('#oem').val();
	$.post(url);
	layer_show(title,url,w,h);
}


function admin_add(title,url,w,h){
	// $.post(url,{"yy":$("#year").val(),"mm":$("#month").val(),"ww":$("#week").val(),"oem":$("#oem").val()});
	// alert($("#year").val());
	// else{
		$.post(url);
		layer_show(title,url,w,h);
	// }
	
}


/*管理员-编辑*/
function admin_edit(title,url,w,h){
    $.get(url); //执行控制器中的编辑操作
	layer_show(title,url,w,h);
}


//批量恢复(原模板中没有,自己动手,丰衣足食)
function unDelete() {

    layer.confirm('确认要恢复吗？', function () {
        $.get("{:url('user/unDelete')}");

        layer.msg('已恢复!', {icon: 1, time: 1000}); //消息弹层1秒后消失
        window.location.reload(); //重新加载页面,显示所有数据
    });
}


</script> 
<!--/请在上方写此页面业务相关的脚本-->
{/block}

</body>
</html>